package com.hongxin.nw.netty.model.packing.info;

import com.hongxin.nw.netty.utils.FieldPack;
import com.hongxin.nw.netty.values.TypeIdentif;
import lombok.extern.slf4j.Slf4j;

/**
 * @remark A.10 充电鉴权下行数据
 * @author: GuoXiaolin
 * @date 2019/5/28 10:05
 * @Version 1.0
 * @Descibe
 */
@Slf4j
public class Csdna1_2 implements IPacking {

    private String co;//1	充电设备编号	压缩BCD码	8Byte	充电设备编号
    private String chargeIdentify;//2	充电接口标识	BIN码	1Byte	充电设备为一桩多充时用来标记接口号，一桩一充时此项为0。多个接口时顺序对每个接口进行编号
    private String physicsNum;//3	物理卡号	压缩BCD码	8Byte	16位编码
    private String a;//4	电动汽车唯一标识	字符	32Byte	32位编码，前五位是组织机构编码
    private String billingId;//5	计费模型编码	压缩BCD码	8Byte	8位编码
    private String ye;//6	账户余额	BIN码	4Byte	精确到小数点后两位
    private String successIdentify;//7	鉴权成功标志	BIN码	1Byte	布尔型（1，鉴权成功；0，鉴权失败）
    //5001:无效卡号
    //5003:余额不足
    //5004:卡锁住
    //5007:无效卡
    //5011:套餐余额不足
    //5015:无效车状态
    //5016:无效账户状态
    //5017:密码错误一次
    //5018:密码错误两次
    //5019:密码错误三次
    //5099:系统错误
    private String failIdentify;//8	鉴权失败原因	压缩BCD码 	2Byte
    private String SyLc;//9	剩余里程	BIN码	4Byte	精确到小数点后两位
    private String KcDl;//10	可充电量	BIN码	4Byte	精确到小数点后两位
    private String SyCs;//11	剩余次数	BIN码	4Byte	精确到小数点后两位

    public Csdna1_2 setCo(String co) {
        this.co = FieldPack.caseToBCD(co, TypeIdentif.BYTE_CO.getByteLength());
        return this;
    }

    public Csdna1_2 setChargeIdentify(String chargeIdentify) {
        this.chargeIdentify = FieldPack.caseToBin(chargeIdentify, TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getByteLength());
        return this;
    }

    public Csdna1_2 setPhysicsNum(String physicsNum) {
        this.physicsNum =  FieldPack.caseToBCD(physicsNum, TypeIdentif.BYTE_CARD.getByteLength());
        return this;
    }
    public Csdna1_2 setA(String a) {
        this.a =  FieldPack.caseToVin(a, TypeIdentif.BYTE_CAR_IDENTIFY_32.getByteLength());
        return this;
    }
    public Csdna1_2 setBillingModel(String billingId) {
        this.billingId = FieldPack.caseToBCD(billingId, TypeIdentif.BYTE_BILLING_MODEL_ID.getByteLength());
        return this;
    }
    public Csdna1_2 setYe(double ye) {
        this.ye = FieldPack.decimalToHex(ye, 2, TypeIdentif.BYTE_ACCOUNT_MONEY.getByteLength());
        return this;
    }

    public Csdna1_2 setSuccessIdentify(String successIdentify) {
        this.successIdentify = FieldPack.caseToBin(successIdentify, TypeIdentif.BYTE_SUCCESS_IDENTIFY.getByteLength());
        return this;
    }
    public Csdna1_2 setFailIdentify(String failIdentify) {
        this.failIdentify = FieldPack.caseToBCD(failIdentify, TypeIdentif.BYTE_AUTH_FAIL_IDENTIFY.getByteLength());
        return this;
    }
    public Csdna1_2 setSyLc(double SyLc) {
        this.SyLc =  FieldPack.decimalToHex(SyLc, 2, TypeIdentif.BYTE_SURPLUS_MILEAGE.getByteLength());
        return this;
    }
    public Csdna1_2 setKcDl(double KcDl) {
        this.KcDl =  FieldPack.decimalToHex(KcDl ,2, TypeIdentif.BYTE_K_C_D_L.getByteLength());
        return this;
    }
    public Csdna1_2 setSyCs(double SyCs) {
        this.SyCs =  FieldPack.decimalToHex(SyCs ,2, TypeIdentif.BYTE_SURPLUS_TIMES.getByteLength());
        return this;
    }

    @Override
    public String packing() {
        return this.co +
                this.chargeIdentify +
                this.physicsNum +
                this.a +
                this.billingId +
                this.ye +
                this.successIdentify +
                this.failIdentify +
                this.SyLc +
                this.KcDl +
                this.SyCs;
    }

    @Override
    public String toString() {
        return "Csdna1_2{" +
                "co='" + co + '\'' +
                ", chargeIdentify='" + chargeIdentify + '\'' +
                ", physicsNum='" + physicsNum + '\'' +
                ", a='" + a + '\'' +
                ", billingId='" + billingId + '\'' +
                ", ye='" + ye + '\'' +
                ", successIdentify='" + successIdentify + '\'' +
                ", failIdentify='" + failIdentify + '\'' +
                ", SyLc='" + SyLc + '\'' +
                ", KcDl='" + KcDl + '\'' +
                ", SyCs='" + SyCs + '\'' +
                '}';
    }
}
